package com.example.demo.Controller;

import com.example.demo.config.DataSource;
import com.example.demo.config.DataSourceUtil;
import com.example.demo.core.UserInfo;
import com.example.demo.server.AreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * TODO
 *
 * @ClassName test
 * @Author: HanQiCheng
 * @DateTime: 2022/7/26 11:19
 */
@RestController
public class test {

    @Autowired
    private AreaService areaService;

    /**
     * 测试一: 使用DataSourceUtil.setDB("")手动设置数据源
     * @return
     */
    @PostMapping("/test1")
    public List<UserInfo> test1() {
        DataSourceUtil.setDB("db2");
        return areaService.queryAreaLocal();
    }

    /**
     * 测试二: @DataSource设置数据源
     * @return
     */
    @DataSource("db3")
    @PostMapping("/test2")
    public List<UserInfo> test2() {
        return areaService.queryAreaLocal();
    }
}
